--- title: A vector map author: UQGSAC date: '2021-10-28' slug: a-vector-map categories: - spatial - visualisation tags: - RStats - vector ---

Load necessary packages

library(sf)
## Linking to GEOS 3.6.2, GDAL 2.2.3, PROJ 4.9.3
library(tmap)
## Registered S3 methods overwritten by 'stars':
##   method             from
##   st_bbox.SpatRaster sf  
##   st_crs.SpatRaster  sf

Get the data

The process to get the data is stored in a script (scripts/get_osm_data.R), instead of integrating it into this R Markdown file. This allows us to not overload the data provider but always querying the API, every single time the article is rendered! (And we don’t need to process the data every time either.)

Here, we only need to read the data from a file:

green_spaces <- st_read("data/green_spaces.geojson")
## Reading layer `green_spaces' from data source 
##   `/home/stragu/r-projects/2021-10-28_UQGSA-blogdown/content/post/2021-10-28-a-vector-map/data/green_spaces.geojson' 
##   using driver `GeoJSON'
## Simple feature collection with 5825 features and 3 fields
## Geometry type: POLYGON
## Dimension:     XY
## Bounding box:  xmin: 152.6764 ymin: -27.67486 xmax: 153.4664 ymax: -27.00613
## CRS:           4326

Visualise on a slippy map

The tmap package is useful to visualise vector data on a slippy map.

tmap_mode("view")
## tmap mode set to interactive viewing
tm_shape(green_spaces) +
  tm_polygons()